use Test::More;

use Customer;
use Rental;
use Movie;
use strict;
use warnings;

my $customer = undef;
my $movie = undef;
my $rental = undef;

# 检查顾客名fuxuewei
$customer = Customer->new( _name => 'fuxuewei');
$movie = Movie->new( _title => 'Home', _price_code => $Movie::REGULAR);
$rental = Rental->new( _movie => $movie, _days_rented => 10 );
$customer->add_rental($rental);

like($customer->statement(), qr/Rental Record for fuxuewei/ms, 'Check the Customer name fuxuewei');

# 检查顾客名luoyuanyuan
$customer = Customer->new( _name => 'luoyuanyuan');
$movie = Movie->new( _title => 'Home', _price_code => $Movie::REGULAR);
$rental = Rental->new( _movie => $movie, _days_rented => 10 );
$customer->add_rental($rental);

like($customer->statement(), qr/Rental Record for luoyuanyuan/ms, 'Check the Customer name luoyuanyuan');

# 检查顾客名luoyuanyuan, 电影名Home
$customer = Customer->new( _name => 'luoyuanyuan');
$movie = Movie->new( _title => 'Home', _price_code => $Movie::REGULAR);
$rental = Rental->new( _movie => $movie, _days_rented => 10 );
$customer->add_rental($rental);

like($customer->statement(), qr/Home/ms, 'Check the movie name Home');

my $movie_2;
my $rental_2;
# 检查顾客名luoyuanyuan, 两部电影名Home, Country
$customer = Customer->new( _name => 'luoyuanyuan');
$movie = Movie->new( _title => 'Home', _price_code => $Movie::REGULAR);
$rental = Rental->new( _movie => $movie, _days_rented => 10 );
$movie_2 = Movie->new( _title => 'Country', _price_code => $Movie::REGULAR);
$rental_2 = Rental->new( _movie => $movie_2, _days_rented => 10 );
$customer->add_rental($rental);
$customer->add_rental($rental_2);

like($customer->statement(), qr/(Home.*Country)/ms, 'Check the movie name Home and Country');

# 检查顾客名fuxuewei，一部普通电影名Children，租期2天，租金2元
$customer = Customer->new( _name => 'fuxuewei');
$movie = Movie->new( _title => 'Children', _price_code => $Movie::REGULAR);
$rental = Rental->new( _movie => $movie, _days_rented => 2 );
$customer->add_rental($rental);

like($customer->statement(), qr/Rental Record for fuxuewei.+Children.+2.+Amount owed is 2.+You earned 1/ms, 'Check the Customer name fuxuewei, movie Children, rent 2 day');

# 检查顾客名fuxuewei，一部普通电影名Children，租期5天，租金5元
$customer = Customer->new( _name => 'fuxuewei');
$movie = Movie->new( _title => 'Children', _price_code => $Movie::REGULAR);
$rental = Rental->new( _movie => $movie, _days_rented => 5 );
$customer->add_rental($rental);

like($customer->statement(), qr/Rental Record for fuxuewei.+Children.+5.+Amount owed is 5.+You earned 1/ms, 'Check the Customer name fuxuewei, regular movie Children, rent 5 day');

# 检查顾客名fuxuewei，两部普通电影名Children、Dog，租期5天，租金各5元
$customer = Customer->new( _name => 'fuxuewei');
$movie = Movie->new( _title => 'Children', _price_code => $Movie::REGULAR);
$rental = Rental->new( _movie => $movie, _days_rented => 5 );
$movie_2 = Movie->new( _title => 'Dog', _price_code => 0);
$rental_2 = Rental->new( _movie => $movie_2, _days_rented => 5 );
$customer->add_rental($rental);
$customer->add_rental($rental_2);

like($customer->statement(), qr/Rental Record for fuxuewei.+Children.+5.+Dog.+5.+Amount owed is 10.+You earned 2/ms, 'Check the Customer name fuxuewei, regular movie Children and Dog, rent 5 day');

# 检查顾客名fuxuewei，一部新发行的电影名Stars，租期5天，租金15元
$customer = Customer->new( _name => 'fuxuewei');
$movie = Movie->new( _title => 'Stars', _price_code => $Movie::NEW_RELEASE);
$rental = Rental->new( _movie => $movie, _days_rented => 5 );
$customer->add_rental($rental);

like($customer->statement(), qr/Rental Record for fuxuewei.+Stars.+15.+Amount owed is 15.+You earned 2/ms, 'Check the Customer name fuxuewei, new realease movie Stars, rent 5 day');


# 检查顾客名fuxuewei，两部新发行的电影名Stars和Moon，租期5天，租金15元
$customer = Customer->new( _name => 'fuxuewei');
$movie = Movie->new( _title => 'Stars', _price_code => $Movie::NEW_RELEASE);
$rental = Rental->new( _movie => $movie, _days_rented => 5 );
$movie_2 = Movie->new( _title => 'Moon', _price_code => $Movie::NEW_RELEASE);
$rental_2 = Rental->new( _movie => $movie_2, _days_rented => 5 );
$customer->add_rental($rental);
$customer->add_rental($rental_2);

like($customer->statement(), qr/Rental Record for fuxuewei.+Stars.+15.+Moon.+15.+Amount owed is 30.+You earned 4/ms, 'Check the Customer name fuxuewei, new realease movie Stars and Moon, rent 5 day');

# 检查顾客名fuxuewei，一部儿童电影名Toys，租期2天，租金1元
$customer = Customer->new( _name => 'fuxuewei');
$movie = Movie->new( _title => 'Toys', _price_code => $Movie::CHILDREN);
$rental = Rental->new( _movie => $movie, _days_rented => 2 );
$customer->add_rental($rental);

like($customer->statement(), qr/Rental Record for fuxuewei.+Toys.+1.+Amount owed is 1.+You earned 1/ms, 'Check the Customer name fuxuewei, Children movie Toys, rent 2 day');

# 检查顾客名fuxuewei，一部儿童电影名Toys，租期5天，租金3元
$customer = Customer->new( _name => 'fuxuewei');
$movie = Movie->new( _title => 'Toys', _price_code => $Movie::CHILDREN);
$rental = Rental->new( _movie => $movie, _days_rented => 5 );
$customer->add_rental($rental);

like($customer->statement(), qr/Rental Record for fuxuewei.+Toys.+3.+Amount owed is 3.+You earned 1/ms, 'Check the Customer name fuxuewei, Children movie Toys, rent 5 day');

my $movie_3;
my $rental_3;
# 检查顾客名luoyuanyuan，一部新电影New，一部普通电影Common,一部儿童电影Play，租期都是2天
$customer = Customer->new( _name => 'fuxuewei');
$movie = Movie->new( _title => 'New', _price_code => $Movie::NEW_RELEASE);
$rental = Rental->new( _movie => $movie, _days_rented => 2 );
$movie_2 = Movie->new( _title => 'Common', _price_code => $Movie::REGULAR);
$rental_2 = Rental->new( _movie => $movie_2, _days_rented => 2 );
$movie_3 = Movie->new( _title => 'Play', _price_code => $Movie::CHILDREN);
$rental_3 = Rental->new( _movie => $movie_3, _days_rented => 2 );
$customer->add_rental($rental);
$customer->add_rental($rental_2);
$customer->add_rental($rental_3);

like($customer->statement(), qr/Rental Record for fuxuewei.+New.+6.+Common.+2.+Play.+1.+Amount owed is 9.+You earned 4/ms, 'Check the Customer name fuxuewei, new realease movie New and Regular movie Common and Children Movie Play, rent 2 day');


done_testing();

1;